unit EtiquetaZebra;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Mask, ToolEdit, CurrEdit, StdCtrls, Buttons, ExtCtrls;

type
  TfrmEtqZebra = class(TForm)
    ed1: TEdit;
    ed2: TEdit;
    edQtde: TCurrencyEdit;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Bevel1: TBevel;
    Bevel2: TBevel;
    BitBtn2: TBitBtn;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmEtqZebra: TfrmEtqZebra;

implementation

uses clsParametros, Biblio;

{$R *.DFM}

procedure TfrmEtqZebra.BitBtn1Click(Sender: TObject);
var
  Arq, F: TextFile;
  PortaImpr, texto: string;
  Par: TParametros;
  i: integer;
  impr: Boolean;
begin
  Par := TParametros.Create;
  Par.Recuperar('1');
  if FileExists(Par.Repos_personal + 'HB') then begin
    if FileExists(Par.Repos_personal + 'Zebra.imp') then begin
      AssignFile(Arq, Par.Repos_personal + 'Zebra.imp');
      Reset(Arq);
      Readln(Arq, texto);
      case StrToInt(copy(texto, 1, 1)) of
        0: PortaImpr := 'COM1';
        1: PortaImpr := 'COM2';
        2: PortaImpr := 'COM3';
        3: PortaImpr := 'LPT1';
        4: PortaImpr := 'LPT2';
        5: PortaImpr := 'LPT3';
      end;
      CloseFile(Arq);
    end;
  end;

  AssignFile(F, PortaImpr);
  Rewrite(F);
  //CopyFile(StrToPChar('C:\FOTO.GRF'),StrToPChar(PortaImpr),True);
  for i := 0 to iv(edQtde.Value - 1) do begin
    impr := False;
    if i mod 2 = 0 then begin
      Writeln(F, '^XA');
      Writeln(F, '^LH16,32');
      Writeln(F, '^LL1280');
      Writeln(F, '^FO320,035^ADR,37,21^FD' + Center(ed1.Text, 48) + '^FS');
      Writeln(F, '^FO060,035^ADR,37,21^FD' + Center(ed2.Text, 48) + '^FS');

      {Writeln(F,'^FO035,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO085,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO135,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO185,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO235,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO285,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO350,035^ADR,37,21^FD'+ed1.Text+'^FS'); }

    end else begin
      Writeln(F, '^FO760,035^ADR,37,21^FD' + Center(ed1.Text, 48) + '^FS');
      Writeln(F, '^FO500,035^ADR,37,21^FD' + Center(ed2.Text, 48) + '^FS');

      {Writeln(F,'^FO760,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO710,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO660,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO610,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO560,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO510,035^ADR,28,15^FD'+ed2.Text+'^FS');
      Writeln(F,'^FO445,035^ADR,37,21^FD'+ed1.Text+'^FS');}

      impr := True;
    end;
    if impr then
      Writeln(F, '^XZ');
  end;

  CloseFile(F);
  Par.Free;
end;

procedure TfrmEtqZebra.BitBtn2Click(Sender: TObject);
begin
  close;
end;

end.
